package cn.g31010.sip.service
{
	import cn.g31010.sip.model.*;
	import cn.g31010.sip.vo.User;
	
	import mx.controls.Alert;
	
	public class AuthService
	{
		private static var authservice:AuthService;
		public function AuthService()
		{
			if(AuthService.authservice!=null)
				throw new Error("Only one instance should be instantiated");
		}
		
		public static function getInstance():AuthService{
			if(authservice==null){
				authservice=new AuthService;
			}
			return authservice;
		}
		private var usermodel:UserModel=UserModel.getInstance();
		
		public function auth(id:String,passwd:String,callback:Function=null):User{
			var client:HessianClient=new HessianClient("AuthService",callback==null?authResp:callback);
			client.request("auth",id,passwd);
			return null;
		}

		private function authResp(obj:Object):void{
			var user:User = User.create(obj);
			usermodel.currentUser=user;
			mx.controls.Alert.show(user.toString());
		}
	}
}